package com.xingxing.Fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.xingxing.Activity.databinding.FragmentMessageBinding;
import com.xingxing.Adapter.DikDokAdapter;
import com.xingxing.Adapter.MessageAdapter;
import com.xingxing.Bean.Likes;
import com.xingxing.Bean.Video;
import com.xingxing.Interface.OkSuccessInterface;
import com.xingxing.Util.APIConfig;
import com.xingxing.Util.CommonUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import static com.xingxing.Util.CommonUtils.GetUserInfo;

public class MessageFragment extends Fragment {
    ArrayList<Likes> likes;
    private FragmentMessageBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = FragmentMessageBinding.inflate(inflater, container, false);
        View root = binding.getRoot();
        binding.recyclerviewMessage.setLayoutManager(new LinearLayoutManager(getContext()));

        Map<String, Object> map = new HashMap<>();
        map.put("type","getLike");
        map.put("userAccount", Objects.requireNonNull(GetUserInfo()).getUserAccount());
        CommonUtils.OKJsonPost(getActivity(), new Gson().toJson(map), APIConfig.GetLike, new OkSuccessInterface() {
            @Override
            public void OnSuccess(String json) {
                likes = new Gson().fromJson(json, new TypeToken<ArrayList<Likes>>() {
                }.getType());
                MessageAdapter messageAdapter = new MessageAdapter(getContext(), json);
                binding.recyclerviewMessage.setAdapter(messageAdapter);
            }
        });
        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}